package com.wzh.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * 数据库有关工具类<br>
 * 连接数据库
 * @author wzh
 *
 */
public class DBUtil {
	public static final String url = "jdbc:mysql://127.0.0.1/test";  
    public static final String name = "com.mysql.cj.jdbc.Driver";  
    public static final String user = "root";  
    public static final String password = "wang1875";  
  
    public Connection conn = null;  
    public PreparedStatement pst = null; 
//	private String url="";
//	private String userName="";
//	private String password="";
	
	private Connection connection;

	public DBUtil(String sql) {
		try {
			System.out.println("================");
			Class.forName(name);//指定连接类型  
            conn = DriverManager.getConnection(url, user, password);//获取连接  
            pst = conn.prepareStatement(sql);//准备执行语句 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	
//	public DBUtil(String url,String userName,String password){
//		this.url=url;
//		this.userName=userName;
//		this.password=password;
//	}
//	
//	public Connection getConnection(){
//		return connection;
//	}
	 public void close() {  
	        try {  
	            this.conn.close();  
	            this.pst.close();  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	    }  
	
}
